<?php

use app\enum\LogRegType;
?>
<style>
    .layui-form-label {
        width: 120px;
    }

    .layui-input-block {
        margin-left: 150px;
    }
</style>
<div class="rightcontent rc-bg-grey">
    <div class="rc-pagepadding">
        <div class=" rc-pannel ">
            <div class=" rc-pannel-header rc-pagepadding rc-bold">
                用户登录注册相关配置
                <a style="font-weight:500;margin-left:10px" class="primary" href="/admin/cnf/Syscnf/index" target="_blank"> 请先配置用户中心相关参数</a>
            </div>

            <div class="rc-pannel-body layui-form rc-pagepadding">


                <form class="layui-form" action="">

                    <div class="layui-form-item">
                        <label class="layui-form-label">开放注册 <i class="layui-icon layui-icon-question rc-tips rc-pointer" message="关闭注册后面的设置不起作用" style=" color: #7D8388;"></i> </label>
                        <div class="layui-input-block">
                            <input type="radio" autocomplete="off" checked name="openreg" <?php echo isset($config['openreg']) && $config['openreg'] == 1 ? 'checked' : '' ?> lay-verify="required" value="1" class="layui-input" title="开放" lay-filter="required">
                            <input type="radio" autocomplete="off" name="openreg" <?php echo isset($config['openreg']) && $config['openreg'] == -1 ? 'checked' : '' ?> lay-verify="required" value="-1" class="layui-input" title="关闭" lay-filter="required">
                        </div>


                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">登录方式 <i class="layui-icon layui-icon-question rc-tips rc-pointer" message="如果同时选中，手机免密登录需要绑定用户名。选择手机免密登录，验证码必须选择手机短信验证" style=" color: #7D8388;"></i> </label>
                        <div class="layui-input-block">

                            <?php
                            $logregtypes = [];
                            if (isset($config['logregtype'])) {
                                $logregtypes = explode(',', $config['logregtype']);
                            } ?>
                            <input type="checkbox" autocomplete="off" name="logregtype[]" lay-verify="required" value="1" <?php echo in_array(1, $logregtypes) ? 'checked' : ''; ?> class="layui-input" title="用户名密码" lay-filter="logregtype">
                            <input type="checkbox" autocomplete="off" name="logregtype[]" lay-verify="required" value="2" <?php echo in_array(2, $logregtypes) ? 'checked' : ''; ?> class="layui-input" title="手机免密" lay-filter="logregtype">


                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">验证码 <i class="layui-icon layui-icon-question rc-tips rc-pointer" message="选择手机或邮箱验证必须在注册模型中启用此字段"></i></label>
                        <div class="layui-input-block">
                            <input type="radio" name="captchatype" value="1" <?php echo isset($config['captchatype']) && $config['captchatype'] == 1 ? 'checked' : '' ?> lay-verify="required" class="layui-input" title="图形验证">
                            <input type="radio" name="captchatype" value="2" <?php echo isset($config['captchatype']) && $config['captchatype'] == 2 ? 'checked' : '' ?> lay-verify="required" class="layui-input" title="手机短信">
                            <input type="radio" name="captchatype" value="3" <?php echo isset($config['captchatype']) && $config['captchatype'] == 3 ? 'checked' : '' ?> lay-verify="required" class="layui-input" title="邮箱验证">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">找回密码 <i class="layui-icon layui-icon-question rc-tips rc-pointer" message="选中某个选项后，注册模型中必须启用此字段"></i></label>
                        <div class="layui-input-block">
                            <?php
                            $forgetpwds = [];
                            if (isset($config['forgetpwd'])) {
                                $forgetpwds = explode(',', $config['forgetpwd']);
                            } ?>


                            <input type="checkbox" name="forgetpwd[]" lay-verify="required" value="1" <?php echo in_array(1, $forgetpwds) ? 'checked' : ''; ?> class="layui-input" title="手机">
                            <input type="checkbox" name="forgetpwd[]" lay-verify="required" value="2" <?php echo in_array(2, $forgetpwds) ? 'checked' : ''; ?> class="layui-input" title="邮箱">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">必须完善资料</label>
                        <div class="layui-input-block">
                            <input type="radio" name="mustperfected" lay-verify="required" <?php echo isset($config['mustperfected']) && $config['mustperfected'] == 1 ? 'checked' : '' ?> value="1" class="layui-input" title="是">
                            <input type="radio" name="mustperfected" lay-verify="required" <?php echo isset($config['mustperfected']) && $config['mustperfected'] == 1 ? 'checked' : '' ?> value="-1" checked class="layui-input" title="否">
                        </div>
                    </div>




                    <div class="layui-form-item rc-margin-bottom0">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">提交</button>
                            <button type="reset" class="layui-btn layui-btn-sm">重置</button>
                        </div>
                    </div>
                </form>

            </div>
        </div>
    </div>
</div>
<script>
    layui.use(function() {
        var form = layui.form;


        form.on('checkbox(logregtype)', function(data) {
            var elem = data.elem; // 获得 checkbox 原始 DOM 对象
            var checked = elem.checked; // 获得 checkbox 选中状态
            var value = elem.value; // 获得 checkbox 值
            var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象


            if (value == 2 && checked) {
                //设置验证码只能选择手机短信
                $('input[name="captchatype"]').prop('disabled', true);
                $('input[name="captchatype"][value="2"]').prop('checked', true);
                form.render();
            }

            if (value == 2 && !checked) {
                $('input[name="captchatype"]').prop('disabled', false);
                form.render();
            }

        });

        form.on('submit(submit)', function(data) {
            $.ajax({
                url: '/admin/cnf/UserLogregConfig/index', //请求路径
                type: "POST", //请求方式
                data: data.field, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success("设置成功", function() {
                            window.parent.location.reload();
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });
        });

    });
</script>